import { TypeOrmModuleOptions } from '@nestjs/typeorm'
import { SnakeNamingStrategy } from 'typeorm-naming-strategies'
import config from '../../config'

export const getTypeOrmConfig = (): TypeOrmModuleOptions => ({
  type: 'mysql',
  host: config.database.host,
  port: Number(config.database.port),
  username: config.database.username,
  password: config.database.password,
  database: config.database.database,
  entities: config.database.entities,
  synchronize: config.database.synchronize,
  logging: config.database.logging,
  namingStrategy: new SnakeNamingStrategy(), // 自动驼峰转下划线
  // ...(config.database.migrations && { migrations: config.database.migrations }),
  // ...(config.database.cli && { cli: config.database.cli }),
})
